package com.party.mobile.biz.photo;

import com.party.common.paging.Page;
import com.party.common.utils.StringUtils;
import com.party.core.exception.BusinessException;
import com.party.core.model.photo.PhotosMemberOperate;
import com.party.core.model.photo.PhotosRankOutput;
import com.party.core.service.photo.IPhotosMemberOperateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description:
 * @Author: yangshoukun
 * @Date: 2018/6/5 10:01
 */
@Service
public class RankBizService {

    @Autowired
    private IPhotosMemberOperateService photosMemberOperateService;

    /**
     * 排名列表
     * @param operate
     * @param page
     * @return
     */
    public List<PhotosRankOutput> list(PhotosMemberOperate operate, Page page) {
        if (StringUtils.isEmpty(operate.getPhotosId())) {
            throw new BusinessException("相册id不能为空");
        }
        return photosMemberOperateService.rankPage(operate, page);
    }

    /**
     * 获取自己排名
     * @param operate
     * @return
     */
    public PhotosRankOutput self(PhotosMemberOperate operate) {
        if (StringUtils.isEmpty(operate.getPhotosId())) {
            throw new BusinessException("相册id不能为空");
        }
        if (StringUtils.isEmpty(operate.getMemberId())) {
            throw new BusinessException("用户id不能为空");
        }
        PhotosMemberOperate param = new PhotosMemberOperate();
        param.setPhotosId(operate.getPhotosId());
        param.setMemberId(operate.getMemberId());
        List<PhotosRankOutput> list = photosMemberOperateService.rankPage(param, null);
        if (list.size() > 0) {
            return list.get(0);
        }
        return null;
    }
}
